<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);  
include_once dirname(dirname(dirname(__FILE__))).'/mgtv_init.php';
include_once dirname(dirname(dirname(__FILE__))) .'/models/queue_task_model.php';
define('ORG_ID', 'sihua_huawei');

class import_csv extends nn_timer
{

    public function action($params = null)
    {
        $this->msg('开始执行...');
        do_timer_action();
        $this->msg('执行结束...');
    }
}
$import_csv = new import_csv("import_csv", ORG_ID);
$import_csv->run();

function do_timer_action()
{
    set_time_limit(0);
    $db = nn_get_db(NL_DB_WRITE);
    $db->open();
    $queue_task_model = new queue_task_model();
    $file = fopen("a.csv","r");
    while(! feof($file)){
        $arr = (fgetcsv($file));
        $video_id = trim($arr[0]);
        if($video_id)
        {
            $sql="select nns_id from nns_vod where nns_id='$video_id'";
            $vod_info = nl_db_get_col($sql, $db);
            if($vod_info){
                $queue_task_model->q_add_task($video_id,'video','add','shanghai_mobile');
                $queue_task_model->q_add_task($video_id,'video','add','sihua');
                	
                $sql_index = "select nns_id from nns_vod_index where nns_vod_id='$video_id' and nns_deleted!=1";
                $indexs = nl_db_get_all($sql_index, $db);
                	
                if(is_array($indexs))
                {
                    foreach ($indexs as $val_index) {
                        $queue_task_model->q_add_task($val_index['nns_id'],'index','add','shanghai_mobile');
                        $queue_task_model->q_add_task($val_index['nns_id'],'index','add','sihua');
                    }
                }
                	
                $sql_media = "select nns_id from nns_vod_media where nns_vod_id='$video_id' and nns_deleted!=1";
                $medias = nl_db_get_all($sql_media, $db);
                	
                if(is_array($medias))
                {
                    foreach ($medias as $val_media) {
                        $queue_task_model->q_add_task($val_media['nns_id'],'media','add','shanghai_mobile');
                        $queue_task_model->q_add_task($val_media['nns_id'],'media','add','sihua');
                    }
                }
            }
    
        }
    }
    fclose($file);
}



